<!--
 * @Author: zy
 * @Date: 2021-07-29 15:37:47
 * @LastEditTime: 2021-07-29 15:37:47
 * @Description: 前科情况登记
 * @LastEditors: zy
-->
<template>
  <basic-container v-loading="loading" element-loading-text="数据加载中...">
    <dataList
      placeholder="请输入姓名"
      searchName="name"
      :pageInfo="pager"
      :listData="tableData"
      :filterList="filterList"
      :selectData="selectDataArr"
      :menuList="[]"
      :dataInfo="dataInfo"
      :operaInfo="operaInfo"
      operaColumnWidth="140"
      :openIndex="true"
      @btn-click="handleBtnClick"
    ></dataList>
    <!-- 新增|编辑|查看 单位 -->
    <Adialog ref="adialog" @submit="submit" />
  </basic-container>
</template>

<style lang="scss" scoped>
.operateMain {
  /deep/ .top-buttons {
    float: right;
    width: 50%;
  }
  /deep/ .v-search {
    width: 50%;
    justify-content: flex-start;
  }
  /deep/ .operaColumn .el-button {
    color: var(--color);
    text-align: center;
  }
}
</style>


<script>
import {
  getpagequery
} from "@/views/yq-personnel/api/health.js";
import Adialog  from "./dialog.vue";
import { extractName } from "@/utils/extract";
import dateFormate from "@/assets/js/date";
export default {
  components: {  Adialog },
  provide() {
    return {
      initList: this.queryData,
      personId: () => this.currentPersonId,
      moveInfoId: () => this.currentMoveInfoId,
      hotelBaseInfoId: () => this.currentHotelBaseInfoId,
    };
  },
  beforeMount() {
    // 请求列表数据
    this.queryData();
  },
  data() {
    return {
      // 表格列表数据
      tableData: [],
      currentPersonId: "",
      currentMoveInfoId: "",
      currentHotelBaseInfoId: "",
      // 请求参数
      params: {
        current: 1,
        size: 20,
        keyword: "",
      },
      // 选中的数据
      selectDataArr: [],
      // 分页
      pager: {
        total: 0, // 总页数
        current: 1, // 当前页数
        size: 20, // 每页显示多少条
      },
      // 页面loading
      loading: false,
      hotelList: [],
      // 筛选项
      componentIds: [4, 5, 6, 7],
    };
  },
  // 控制显示的内容
  computed: {
    // 操作按钮
    operaInfo() {
      return [
        {
          label: "违法犯罪前科情况登记",
          name: "add",
        },
        "preview",
      ];
    },
    // 筛选项
    filterList() {
      return [
        { label: "电话号码", inputType: "input", name: "telPhone" },
        { label: "房号", inputType: "input", name: "roomNum" },
        {
          label: "入住时间",
          inputType: "daterange",
          name: ["moveStartTime", "moveEndTime"],
        },
        {
          label: "人员类型",
          inputType: "dict",
          name: "personClassify",
          dictName: "person_classify",
        },
      ];
    },
    dataInfo() {
      return [
        { label: "隔离点名称", prop: "hotelName" },
        { label: "房号", prop: "roomNum", width: "80px", sortable: true },
        { label: "姓名", prop: "name", width: "100px" },
        { label: "电话号码", prop: "telPhone", width: "160px" },
        {
          label: "入住开始时间",
          prop: "moveStartTime",
          formatter: this.dataFormatter,
          sortable: true,
        },
        {
          label: "入住终止时间",
          prop: "moveEndTime",
          formatter: this.dataFormatter,
          sortable: true,
        },
        {
          label: "人员类型",
          prop: "personClassify",
          formatter: this.dataFormatter,
          "show-overflow-tooltip": true, // 请求接口
        },
        {
          label: "心里评估等级",
          prop: "assessmentRiskLevel",
        },
        {
          label: "是否关爱人员",
          prop: "sign",
          formatter: this.dataFormatter,
        },
        {
          label: "人员状态",
          prop: "personState",
          formatter: this.dataFormatter,
        },
      ];
    },
  },
  methods: {
    submit() {
      this.queryData();
    },
    //格式化表格字典值
    dataFormatter(row, column, cellValue) {
      switch (column.property) {
        case "cardType":
          return extractName("card_type", row.cardType);
        case "personState":
          return extractName("person_state", row.personState);
        case "personClassify":
          return extractName("person_classify", row.personClassify);
        case "moveStartTime":
          return (
            row.moveStartTime &&
            dateFormate.datasng(row.moveStartTime, "yyyy-MM-dd hh:mm")
          );
        case "moveEndTime":
          return (
            row.moveEndTime &&
            dateFormate.datasng(row.moveEndTime, "yyyy-MM-dd hh:mm")
          );
        case "sign":
          return row.sign == 1 ? "是" : "否";
        default:
          break;
      }
    },
    // 数据请求
    queryData(params = {}) {
      this.loading = true;
      let requestData = { ...this.params, ...params };
      requestData.qt = "ycpc";
      !requestData.personState && (requestData.personState = "21,22");

      if (requestData.signingDateStart == "") {
        delete requestData.signingDateStart;
      }
      if (requestData.signingDateEnd == "") {
        delete requestData.signingDateEnd;
      }
      getpagequery(requestData)
        .then((res) => {
          const { current, size, total, records } = res.data.data;
          this.tableData = records;
          this.params = requestData;
          this.pager = { total, current, size };
        })
        .finally(() => {
          this.loading = false;
        });
    },
    deleteData(id) {},
    //表格按钮点击事件监听
    handleBtnClick({ type, row }) {
      this.currentMoveInfoId = row.moveInfoId;
      this.currentPersonId = row.personId;
      this.currentHotelBaseInfoId = row.hotelBaseInfoId;
      switch (type) {
        //查看
        case "preview":
          this.$refs.adialog.changeVisible({ type, row });
          break;
        // 异常登记
        case "add":
          this.currentPersonId = row.personId;
          this.$refs.adialog.changeVisible({ type, row });
          break;
        default:
          break;
      }
    },

  },
};
</script>
